package com.ruibang.glass.material.controller.warehousemanage;


import com.ruibang.glass.material.constant.Constants;
import com.ruibang.glass.material.domain.req.MaterialCheckManagementReq;
import com.ruibang.glass.material.entity.MaterialWarehouseInventoryCheck;
import com.ruibang.glass.material.service.MaterialWarehouseInventoryCheckService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 仓库盘点 前端控制器
 * </p>
 *
 * @author mameng
 * @since 2024-02-05
 */

@Api(tags = "仓库盘点")
@RestController
@RequestMapping("/api/glass/material/check/management/")
public class MaterialCheckManagementController {


    @Autowired
    private MaterialWarehouseInventoryCheckService MaterialWarehouseInventoryCheckService;

    @PostMapping("/list")
    @ApiOperation(value = "获取盘点信息列表", response = ResultBody.class)
    public ResultBody getPageList(@RequestBody MaterialCheckManagementReq materialManagementReq) {
        return ResultBody.success(MaterialWarehouseInventoryCheckService.getPage(materialManagementReq));
    }

    @PostMapping("/add")
    @ApiOperation(value = "新增盘点计划", response = ResultBody.class)
    public ResultBody add(@RequestBody MaterialWarehouseInventoryCheck materialManagement) {
        materialManagement.setStatus(Constants.ONE_STR);
        MaterialWarehouseInventoryCheckService.save(materialManagement);
        return ResultBody.success();
    }

    @GetMapping("/getOne/{id}")
    @ApiOperation(value = "查看盘点计划", response = ResultBody.class)
    public ResultBody updateStatus(@PathVariable("id") String id) {
        return ResultBody.success(MaterialWarehouseInventoryCheckService.getMaterialWarehouseInventoryCheck(id));
    }

    @PostMapping("/updateMaterialWarehouseInventoryCheck")
    @ApiOperation(value = "盘点更新", response = ResultBody.class)
    public ResultBody updateMaterialWarehouseInventoryCheck(@RequestBody MaterialWarehouseInventoryCheck materialManagement) {
        return ResultBody.success(MaterialWarehouseInventoryCheckService.updateById(materialManagement));
    }

    @PostMapping("/updateCheckItem")
    @ApiOperation(value = "跟新盘点库存", response = ResultBody.class)
    public ResultBody updateCheckItem(@RequestBody MaterialWarehouseInventoryCheck materialManagement) {
        MaterialWarehouseInventoryCheckService.updateCheckItem(materialManagement);
        return ResultBody.success();
    }

    @PostMapping("/overCheck")
    @ApiOperation(value = "盘点完成", response = ResultBody.class)
    public ResultBody overCheck(@RequestBody MaterialWarehouseInventoryCheck materialManagement) {
        MaterialWarehouseInventoryCheck byId = MaterialWarehouseInventoryCheckService.getById(materialManagement.getId());
        byId.setStatus(materialManagement.getStatus());
        MaterialWarehouseInventoryCheckService.updateById(byId);
        return ResultBody.success();
    }


}
